package org.xdq.util;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.xdq.base.PageParam;
import org.xdq.base.QueryAction;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;

public class Utils {
	
	
	public static <T> Map<String,Object> getPage(PageParam pageParam,QueryAction<T> action){
		
		PageHelper.startPage(pageParam);
		List<T> list = action.query();
		PageInfo<T> pageInfo = new PageInfo<T>(list);
		
		Map<String,Object> map = new HashMap<String,Object>();
		map.put("rows", pageInfo.getList());
		map.put("pageSize", pageInfo.getPageSize());
		map.put("currSize", pageInfo.getSize());
		map.put("pageNum", pageInfo.getPageNum());
		map.put("pre", pageInfo.getPrePage());
		map.put("next", pageInfo.getNextPage());
		map.put("first", 1);
		map.put("last", pageInfo.getPages());
		map.put("pgTotal", pageInfo.getPages());
		map.put("total", pageInfo.getTotal());
		
		return map;
	}

}
